//
//  WH_QuestionViewController.m
//  App_6.23
//
//  Created by wanghao on 16/6/27.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_QuestionViewController.h"
#import "WH_Question.h"
#import "WH_WebViewController.h"

@interface WH_QuestionViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation WH_QuestionViewController
-(void)viewWillAppear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (_numbID == 1) {
        
        self.title = @"公告";
    }else{
        
        self.title = @"常见问题";

    }
    self.dataArr = [NSMutableArray array];
    [self createTab];
    [self postData];
    [self createHub];
    [self hubShow];
}
-(void)createTab{
    
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.rowHeight = 40;
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
        
    }];
    
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"tab"];
    self.myTableView.tableFooterView = [UIView new];

}
-(void)postData{
    
    NSString *body = [NSString stringWithFormat:@"action=info&cate_id=%ld",_numbID];
    [WH_AppTools postUrl:URLstr body:body result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        
        
        NSDictionary *dic = result;
        NSArray *info_array = [dic objectForKey:@"info_array"];
        for (NSDictionary *dic in info_array) {
            
            WH_Question *question = [WH_Question modelWithDictionary:dic];
            [self.dataArr addObject:question];
        }
        [self hubDismiss];
        [self.myTableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIndex = @"tab";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndex];
    WH_Question *ques = self.dataArr[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld.%@", (indexPath.row+1),ques.title];
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WH_WebViewController *webVC = [[WH_WebViewController alloc] init];
    WH_Question *ques = self.dataArr[indexPath.row];
    webVC.urlStr = ques.content;
    
    [self.navigationController pushViewController:webVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
